//
//  TrackVideoCell.m
//  CoolTennisBall
//
//  Created by CA on 16/3/28.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "TrackVideoCell.h"
#import "TrackVideo.h"
#import <DateTools/DateTools.h>
#import <SDWebImage/UIImageView+WebCache.h>


@interface TrackVideoCell ()
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UIView *maskView;
@property (weak, nonatomic) IBOutlet UIButton *editButton;

@end

@implementation TrackVideoCell

#pragma mark - Public Method

- (void)configureWithTrackVideo:(TrackVideo *)trackVideo isEditting:(BOOL)isEditting indexPath:(NSIndexPath *)indexPath
{
   
    self.maskView.hidden = !trackVideo.isSelected;
    self.editButton.hidden = !isEditting;
    self.nameLabel.text = trackVideo.name;
    self.dateLabel.text = [trackVideo.creatDate formattedDateWithFormat:NSLocalizedString(@"yyyy/MM/dd", nil)];
    self.prevideImageView.image = trackVideo.videoImage;
//    NSLog(@"%zd-%zd-%zd",[User getLastUser].userDevice.oemType,indexPath.row,isEditting);
    
//    NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
//    
//    NSURL *imageUrl = [NSURL fileURLWithPath:[documentPath stringByAppendingPathComponent:trackVideo.imagePath]];
//    
//    [self.prevideImageView sd_setImageWithURL:imageUrl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        if (image == nil) {
//            self.prevideImageView.image = trackVideo.videoImage;
//        }
//    }];
    
}

#pragma mark - Private Method

- (void)prepareForReuse
{
    [super prepareForReuse];
    
    self.maskView.hidden = YES;
    self.editButton.hidden = YES;
    self.nameLabel.text = nil;
    self.dateLabel.text = nil;
    self.prevideImageView.image = nil;
}

#pragma mark - IBAction

- (IBAction)changeName:(id)sender {
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(trackVideoCellDidTouchEditButton:)]) {
        [self.delegate trackVideoCellDidTouchEditButton:self];
    }
}

@end
